<template>
  <div>
    <el-container>
      <el-header class="homeHeader">
        <div class="title">棒棒哒</div>
        <div>
          <el-button type="text" icon="el-icon-bell" style="color: #000000;margin-right: 10px" size="normal" @click="goChat"></el-button>
          <el-dropdown class="userInfo" @command="commandHandler">
            <span class="el-dropdown-link">
              {{user.name}}
              <i>
                <img :src="user.userface" />
              </i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="userinfo">个人信息</el-dropdown-item>
              <el-dropdown-item command="setting">设置</el-dropdown-item>
              <el-dropdown-item divided command="logout">注销</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>

      <el-container>
        <el-aside width="200px">
          <!-- <el-menu @select="menuClick"> -->
          <!--unique-opened 是否只保持一个子菜单的展开-->
          <!-- router 是否使用 vue-router 的模式，启用该模式会在激活导航时以 index 作为 path 进行路由跳转-->
          <el-menu router unique-opened>
            <el-submenu :index="index+''" v-for="(item,index) in routes" :key="index" v-if="!item.hidden">
              <template slot="title">
                <i :class="item.iconCls" style="color: blue;margin-right: 10px"></i>
                <span>{{item.name}}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item :index="child.path" v-for="(child,indexc) in item.children" :key="indexc">{{child.name}}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>

          <el-breadcrumb separator-class="el-icon-arrow-right" v-if="this.$router.currentRoute.path !='/home'">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
          </el-breadcrumb>
          <div class="homeWelcome" v-if="this.$router.currentRoute.path=='/home'">
            袁静棒棒哒
          </div>
          <router-view class="homeRouterView" />
        </el-main>

      </el-container>
      <el-footer class="footer">
        <div style="text-align: center">
          © 2020 烟雨江南
          <el-link href="http://beian.miit.gov.cn/" target="_blank">湘ICP备20010014号</el-link>
        </div>
      </el-footer>
    </el-container>
  </div>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      user: JSON.parse(window.sessionStorage.getItem('user')),
    }
  },
  computed: {
    routes() {
      return this.$store.state.routes
    },
  },
  methods: {
    goChat() {
      this.$router.push('/chat')
    },
    commandHandler(cmd) {
      if (cmd == 'logout') {
        //注销操作
        this.$confirm('此操作将退出登录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(() => {
            this.getRequest('/api/logout')
            window.sessionStorage.removeItem('user')
            this.$store.commit('inintRoutes', []) //清空vuex中的routes数据
            this.$router.replace('/')
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消',
            })
          })
      } else if (cmd == 'userinfo') {
        this.$router.push('/hrinfo')
      }
    },
    // menuClick(index,indexPath){
    //   this.$router.push(index);
    // }
  },
}
</script>

<style scoped>
.homeRouterView {
  margin-top: 10px;
}

.homeHeader {
  background-color: #409eff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0px 15px;
  box-sizing: border-box;
}
.homeHeader .title {
  font-size: 30px;
  font-family: 华文行楷;
  color: #ffffff;
}
.homeHeader .userInfo {
  cursor: pointer;
}
.el-dropdown-link img {
  width: 48px;
  height: 48px;
  border-radius: 24px;
  margin-left: 8px;
}
.el-dropdown-link {
  display: flex;
  align-items: center;
}
.homeWelcome {
  text-align: center;
  font-size: 30px;
  font-family: 华文行楷;
  color: #409eff;
  padding-top: 50px;
}
.footer {
  margin-top: 50px;
  width: 100%;
  text-align: center;
}
</style>